import 'package:flutter/material.dart';

/// @date 2020/08/06  10:34
/// @author 程志强
/// @des 点击、双击、长按

class GestureDetectorClickRoute extends StatefulWidget {
  @override
  _GestureDetectorClickRouteState createState() =>
      _GestureDetectorClickRouteState();
}

class _GestureDetectorClickRouteState extends State<GestureDetectorClickRoute> {
  String _operation = "保存事件名称";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("点击、双击、长按"),
      ),
      body: Center(
        child: GestureDetector(
          child: Container(
            alignment: Alignment.center,
            color: Colors.blue,
            width: 200.0,
            height: 100.0,
            child: Text(_operation, style: TextStyle(color: Colors.white)),
          ),
          onTap: () => updateText("点击"),
          onDoubleTap: () => updateText("双击"),
          onLongPress: () => updateText("长按"),
        ),
      ),
    );
  }

  void updateText(String text) {
    setState(() {
      _operation = text;
    });
  }
}
